package com.luoqiz.design.singleton.type4;

public class SingletonTest04 {
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();

        System.out.println("singleton1 hashcode:" + singleton1.hashCode());
        System.out.println("singleton2 hashcode:" + singleton2.hashCode());
    }
}

//懒汉式 （线程安全，同步）  不推荐    原因：解决了线程安全但是实例化效率太低
class Singleton {

    private static Singleton singleton;

    public static synchronized Singleton getInstance() {
        if (singleton == null) {
            singleton = new Singleton();
        }
        return singleton;
    }

}